package com.itboye.jinpuyiyuan.utils;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;

import com.jude.rollviewpager.RollPagerView;

/**
 * Created by Administrator on 2018/7/4 0004.
 */

public class MyRollViewPager extends RollPagerView {
    int lastX = -1;
    int lastY = -1;
    private float mDownPosX = 0;
    private float mDownPosY = 0;

    public MyRollViewPager(Context context) {
        super(context);
    }

    public MyRollViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyRollViewPager(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }
    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        final float x = ev.getX();
        final float y = ev.getY();

        final int action = ev.getAction();
        switch (action) {
            case MotionEvent.ACTION_DOWN:
                mDownPosX = x;
                mDownPosY = y;

                break;
            case MotionEvent.ACTION_MOVE:
                final float deltaX = Math.abs(x - mDownPosX);
                final float deltaY = Math.abs(y - mDownPosY);
                if (deltaX <deltaY) {
                    return true;
                }
        }

        return super.onInterceptTouchEvent(ev);
    }

//    @Override
//    public boolean dispatchTouchEvent(MotionEvent ev) {
//        int x = (int) ev.getRawX();
//        int y = (int) ev.getRawY();
//        int dealtX = 0;
//        int dealtY = 0;
//
//        switch (ev.getAction()) {
//            case MotionEvent.ACTION_DOWN:
//                getParent().requestDisallowInterceptTouchEvent(true);
//                break;
//            case MotionEvent.ACTION_MOVE:
//                dealtX += Math.abs(x - lastX);
//                dealtY += Math.abs(y - lastY);
//                lastX = x;
//                lastY = y;
//                if (dealtX >= dealtY) { // 左右滑动请求父不要需要拦截
//                    getParent().requestDisallowInterceptTouchEvent(true);
//                } else {
//                    getParent().requestDisallowInterceptTouchEvent(false);
//                    return false;
//                }
//                break;
//            case MotionEvent.ACTION_CANCEL:
//                break;
//            case MotionEvent.ACTION_UP:
//                break;
//
//        }
//        return super.dispatchTouchEvent(ev);
//    }

}
